'''
Created on Jun 1, 2009

@author: mkiyer
'''

import os
import sys
import logging

from veggie.app.application import CommandLineApplication
from veggie.app.chipseq import sw_root

class MACS(CommandLineApplication):
    '''
    classdocs
    '''
    _executable = os.path.join(sw_root, 'MACS', 'current', 'bin', 'macs')

    def get_result_paths(self):
        outfile = self._options['--name'] + '_peaks.xls'
        return [outfile]

    def run(self, t_file, c_file, format="BED", name="macs",
            options=None, args=None, cwd=None):
        if cwd:
            self.cwd = cwd
        if options:
            self.addOptions(options)
        if args:
            self.args = args
        # add options
        self.addOption('--name', name)
        self.addOption('-t', t_file)
        if c_file is not None:
            self.addOption('-c', c_file)
        self.addOption('--format', format)
        # write command line to file
        logging.debug("Command line: %s" % (self.getCommandLine()))
        return self()
